import Vue from 'vue'
import App from './App.vue'
import routes from './routes'
import VueRouter from 'vue-router'
import 'font-awesome/css/font-awesome.min.css'
import Vuex from 'vuex'

import '@/common/js/dialog-full-move'

import 'reset.css/reset.css'
import 'bpmn-js/dist/assets/diagram-js.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css'
import './components/bpmn/assets/css/vue-bmpn.css'

import {postRequest} from "@/api/api";
import {postKeyValueRequest} from "@/api/api";
import {putRequest} from "@/api/api";
import {deleteRequest} from "@/api/api";
import {getRequest} from "@/api/api";

Vue.prototype.postRequest = postRequest;
Vue.prototype.postKeyValueRequest = postKeyValueRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.getRequest = getRequest;

import HashMap from '@/common/HashMap'
Vue.prototype.hashMap=new HashMap()

Vue.use(Vuex)
import store from './vuex/store'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI)
Vue.config.productionTip = false

Vue.use(VueRouter)

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
    if (to.path == '/login') {
        sessionStorage.removeItem('mockUser');
        next();
    }
    /**
     * sessionStorage 用于临时保存同一窗口(或标签页)的数据，在关闭窗口或标签页之后将会删除这些数据
     * localStorage的生命周期是永久的，意思就是如果不主动清除，存储的数据将一直被保存
     */
        //let user = JSON.parse(localStorage.getItem('mockUser'));
    let user = JSON.parse(sessionStorage.getItem('mockUser'));
    if (user!=null&&to.path!='/login') {
        next();
    }else{
        next({path: '/login'});
    }
 /* //NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('mockUser');
    next();
  }
  let user = JSON.parse(sessionStorage.getItem('mockUser'));
  if (user!=null&&to.path!='/login') {
    next();
  }else{
    next({path: '/login'});
  }*/
})

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')


